﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading;
using System.Diagnostics;

using FTG.Testing.Utils;

namespace XTATestRunnerTest {
    [TestClass]
    public class XTATestRunnerTest {

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void RunSTA_InvalidAction() {
            new XTATestRunner().RunSTA(null);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void RunSTA_InvalidApartmentState() {
            new XTATestRunner().Run(()=>{}, ApartmentState.Unknown);
        }

        [TestMethod]
        public void RunSTA_NoException() {
            new XTATestRunner().RunSTA(() => {
                Assert.AreEqual(ApartmentState.STA, Thread.CurrentThread.GetApartmentState());
            });
        }

        [TestMethod]
        [ExpectedException(typeof(DivideByZeroException))]
        public void RunSTA_WithException() {
            new XTATestRunner().RunSTA(() => {
                Assert.AreEqual(ApartmentState.STA, Thread.CurrentThread.GetApartmentState());
                throw new DivideByZeroException();
            });
        }

        [TestMethod]
        public void RunMTA_NoException() {
            new XTATestRunner().RunMTA(() => {
                Assert.AreEqual(ApartmentState.MTA, Thread.CurrentThread.GetApartmentState());
            });
        }

        [TestMethod]
        [ExpectedException(typeof(DivideByZeroException))]
        public void RunMTA_WithException() {
            new XTATestRunner().RunMTA(() => {
                Assert.AreEqual(ApartmentState.MTA, Thread.CurrentThread.GetApartmentState());
                throw new DivideByZeroException();
            });
        }
    }
}
